package shutdown

import (
	"context"
	"forum/pkg/util/logger"
	"net/http"
	"os"
	"os/signal"
	"syscall"
)

func GracefullyShutdown(server *http.Server) {
	// 创建系统信号接收器，接收关闭信号
	done := make(chan os.Signal, 1)
	signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
	<-done

	logger.LoggersObj.Println("closing http server gracefully ...")

	if err := server.Shutdown(context.Background()); err != nil {
		logger.LoggersObj.Fatalln("closing http server gracefully failed:", err)
	}
}
